<template>
  <el-dialog
    :visible="isDialog"
    title="添加电影"
    :modal-append-to-body="false"
    @close="cls('ruleForm')"
  >
    <el-form :model="ruleForm" :rules="rules" label-width="80px" ref="ruleForm">
      <el-form-item label="电影名" prop="movieName">
        <el-input v-model="ruleForm.movieName"></el-input>
      </el-form-item>
      <el-form-item label="海报" prop="poster">
        <img v-if="ruleForm.poster" :src="server+ruleForm.poster" width="100px" height="100px" alt="" />
        <el-upload :action="action" :on-success="successed">
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">
            只能上传jpg/png文件，且不超过500kb，(默认为系统头像)
          </div>
        </el-upload>
      </el-form-item>
      <el-form-item label="导演" prop="director">
        <el-input v-model="ruleForm.director"></el-input>
      </el-form-item>
      <el-form-item label="演员" prop="actor">
        <el-input v-model="ruleForm.actor"></el-input>
      </el-form-item>
      <el-form-item label="片长" prop="long">
        <el-input v-model="ruleForm.long"></el-input>
      </el-form-item>
      <el-form-item label="语言">
        <el-col :span="24">
          <el-select
            v-model="ruleForm.language"
            placeholder="请选择语言"
            style="width: 100%"
            prop="language"
          >
            <el-option
              v-for="item in languageOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-col>
      </el-form-item>
      <el-form-item label="类型">
        <el-col :span="24">
          <el-select
            v-model="ruleForm.type"
            placeholder="请选择类型"
            style="width: 100%"
            prop="type"
          >
            <el-option
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-col>
      </el-form-item>
      <el-form-item label="上映时间" prop="publicDate">
        <el-col :span="24">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="ruleForm.publicDate"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="个性签名" prop="intro">
        <el-input type="textarea" v-model="ruleForm.intro"></el-input>
      </el-form-item>
    </el-form>
    <el-row type="flex" justify="center" align="center">
      <el-col :span="6">
        <el-button @click="cls">取消</el-button>
      </el-col>
      <el-col :span="6">
        <el-button type="primary" @click="add">确定</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import { mapState, mapActions } from 'vuex'
export default {
  computed: {
    ...mapState('movie', ['ruleForm', 'isDialog', 'isAdd'])
  },
  data () {
    return {
      userInfo: {},
      action: '/api/admin/upLoadImg',
      server: 'http://localhost:3000',
      rules: {},
      fileList: [],
      languageOptions: [
        {
          value: '粤语',
          label: '粤语'
        },
        {
          value: '国语',
          label: '国语'
        },
        {
          value: '英语',
          label: '英语'
        },
        {
          value: '日语',
          label: '日语'
        },
        {
          value: '其它',
          label: '其它'
        }
      ],
      typeOptions: [
        {
          value: '动漫',
          label: '动漫'
        },
        {
          value: '言情',
          label: '言情'
        },
        {
          value: '科幻',
          label: '科幻'
        },
        {
          value: '喜剧',
          label: '喜剧'
        },
        {
          value: '爱情',
          label: '爱情'
        },
        {
          value: '剧情',
          label: '剧情'
        },
        {
          value: '动作',
          label: '动作'
        },
        {
          value: '冒险',
          label: '冒险'
        },
        {
          value: '青春',
          label: '青春'
        },
        {
          value: '悬疑',
          label: '悬疑'
        },
        {
          value: '恐怖',
          label: '恐怖'
        },
        {
          value: '其它',
          label: '其它'
        }
      ]
    }
  },
  methods: {
    ...mapActions('movie', ['changeIsDialog', 'changeTime']),
    successed (res) {
      this.server =
        'http://localhost:3000/images/avatar/' + res.data[0].filename
      this.ruleForm.avatar = '/images/avatar/' + res.data[0].filename
    },
    async add () {
      if (this.isAdd) {
        await this.changeTime()
        console.log(this.ruleForm)
        this.$parent.addMovieInfo(this.ruleForm)
      } else {
        this.$parent.edit()
      }
      this.changeIsDialog(false)
    },
    cls () {
      this.changeIsDialog(false)
    }
  }
}
</script>

<style lang="less">
.dialog {
  width: 720px;
  border: 1px solid #000;
  div {
    height: 50px;
    line-height: 50px;
    text-align: center;
  }
}
</style>
